<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<!-- 下载并引入jquery easyUI -->
<link rel="stylesheet" type="text/css"
	href="../../js/jquery-easyui-1.9.5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="../../js/jquery-easyui-1.9.5/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="../../js/jquery-easyui-1.9.5/themes/color.css">
<script type="text/javascript"
	src="../../js/jquery-easyui-1.9.5/jquery.min.js"></script>
<script type="text/javascript"
	src="../../js/jquery-easyui-1.9.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../js/context-menu.js"></script>
</head>
<body>
	<table id="provider_dg" title="供应商管理" class="easyui-datagrid"
		style="width: 550px; height: 250px" url="../provider/list"
		toolbar="#provider_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true" data-options="fit:true">
		<thead>
			<tr>
				<th field="providerNo" width="50">供应商编号</th>
				<th field="provider" width="50">供应商</th>
				<th field="providerAddress" width="50">地址</th>
				<th field="providerEmail" width="50">邮箱</th>
				<th field="providerPhone" width="50">供应商电话</th>
				

			</tr>
		</thead>
	</table>
	<div id="provider_toolbar">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
			onclick="newProvider()">添加</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editProvider()">编辑</a> <a
			href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
			onclick="destroyProvider()">删除</a>
	</div>


	<!-- 新增和修改对话框开始 -->
     <!-- 修改每个组件的id号，增加模块标志信息 -->
     <div id="provider_dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
		closed="true" buttons="#provider_dlg-buttons">
	<div class="ftitle">供应商信息</div>
	<form id="provider_fm" method="post">
		<div class="fitem">
			<label>供应商名称:</label>
			<input name="provider" class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>地&emsp;&emsp;址:</label>
			<input name="providerAddress" class="easyui-textbox">
		</div>
		<div class="fitem">
			<label>邮&emsp;&emsp;箱:</label>
			<input name="providerEmail" class="easyui-validatebox" data-options="required:true,validType:'email'">
		</div>
		<div class="fitem">
			<label>供应商电话:</label>
			<input name="providerPhone" class="easyui-textbox">
		</div>
		
	</form>
	</div>
	<div id="provider_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveProvider()">保存</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#provider_dlg').dialog('close')">取消</a>
	</div>
	
  <!-- 新增和修改对话框结束-->
  
  
  <script type="text/javascript">
   //点击数据表上的新增按钮，会调用这个方法
   function newProvider(){
	    //打开新增对话框
		$('#provider_dlg').dialog('open').dialog('setTitle','新增供应商');
		//新增对话框包含了一个form表单，可能存在多次打开，这里对表单进行清空操作
		$('#provider_fm').form('clear');
		//设置新增数据时提交到服务器的url地址
		url = '../provider/add';
	}
   function editProvider(){
	   var row = $('#provider_dg').datagrid('getSelected');
	   if (row){
	       $('#provider_dlg').dialog('open').dialog('setTitle','编辑供应商信息');
	       $('#provider_fm').form('load',row);
	       url = '../provider/edit?providerNo='+row.providerNo;
	   }else{
		   $.messager.show({
               title: 'Error',
               msg: "选择要修改的供应商信息"
           });
		   }
	}
   function saveProvider(){
	    $('#provider_fm').form('submit',{
	        url: url,
	        onSubmit: function(){
	            return $(this).form('validate');
	        },
	        success: function(result){
	            var result = eval('('+result+')');
	            if (!result.success){
	                $.messager.show({
	                    title: 'Error',
	                    msg: result.errorMsg
	                });
	            } else {
	                $('#provider_dlg').dialog('close');        // close the dialog
	                $('#provider_dg').datagrid('reload');    // reload the user data
	            }
	        }
	    });
	}
   function destroyProvider(){
	   var row = $('#provider_dg').datagrid('getSelected');
	    if (row){
	        $.messager.confirm('Confirm','删除代码加班',function(r){
	            if (r){
	                $.post('../provider/delete',{providerNo:row.providerNo},function(result){
	                    if (result.success){
	                        $('#provider_dg').datagrid('reload');    // reload the user data
	                    } else {
	                        $.messager.show({    // show error message
	                            title: 'Error',
	                            msg: result.errorMsg
	                        });
	                    }
	                },'json');
	            }
	        });
	    }
	}
</body>
</html>